function FormClass () {
	this.prototype = {};
	this.qnty_elem = 'items_qnty';
	this.wrapper = 'items';
	this.ItemNamePrefix = 'item';
	this.action = 'addForm';
	this.PathToAjaxBackend = 'index.php';
	this.FormTemplate = 'form.html';
	this.returned = '';
	this.addForm = function()
	{
		var obj = this;
		var items_qnty = $('#'+obj.qnty_elem).attr("value");
		//alert(items_qnty);
		//action='addForm';
		// Create new JsHttpRequest object.
	    var req = new JsHttpRequest();
	    
	    // Code automatically called on load finishing.
	    req.onreadystatechange = function() {
	        if (req.readyState == 4) {
	            //get errors from backend
	            if(req.responseText)
	            {
	                alert(req.responseText);
	            }
				//get data from backend		
	            else if (req.responseJS.ok == '1')
	            {
				    items_qnty++;
	            	$("#"+obj.wrapper).append(req.responseJS.output);
					$('#'+obj.qnty_elem).attr("value",items_qnty);
					switch(obj.wrapper)
					{
						case 'languages':
							$(".slider")
								.each(function(){
									var id_num = $(this).attr("id").replace(/to_item_languages_grade_(\d+)/,"$1");
									var value = parseInt($("#item_languages_grade_"+id_num).val());
									$(this).slider({
										value: value,
										min:0,
										max:3,
										step:1,
										slide: function(event, ui) {
											$("#item_languages_grade_text_"+id_num).html(grades[ui.value]);
											$("#item_languages_grade_"+id_num).val(ui.value);
										}
									});
								});
							$(".item_languages_title")
								.autocomplete(PathToAjaxBackend, {
							        delay:10,
							        minChars:2,
							        matchSubset:1,
							        autoFill:false,
							        matchContains:1,
							        cacheLength:1,
							        selectFirst:false,
							        formatItem:function(item){return item[0];},
							        maxItemsToShow:10,
							        extraParams:{action:'languageAutocomplete'}
							    })
								.result(function(event,item)
									{
										var id = $(this).attr("id").replace(/item_languages_title_(\d+)/,"$1");
										$("#item_languages_id_"+id).attr("value",item[1]);
									}
								);
						break;
						case 'additionals':
							/*
							$(".item_status")
								.live('click',function()
									{
										$(this).parent().next("input").attr("value",$(this).attr("value"));
										$(this).parent().find(".item_status").removeClass("selectedAction");
										$(this).addClass("selectedAction");
									}
								);
							*/
						break;
						case 'educations':
							$(".item_educations_title")
								.autocomplete(PathToAjaxBackend, {
							        delay:10,
							        minChars:2,
							        matchSubset:1,
							        autoFill:false,
							        matchContains:1,
							        cacheLength:1,
							        selectFirst:false,
							        formatItem:function(item){return item[0];},
							        maxItemsToShow:10,
							        extraParams:{action:'educationAutocomplete'}
							    })
								.result(function(event,item)
									{
										var id = $(this).attr("id").replace(/item_educations_title_(\d+)/,"$1");
										$("#item_educations_edu_id_"+id).attr("value",item[1]);
									}
								);
						break;
						case 'users':
							$(".item_company_user")
								.autocomplete(PathToAjaxBackend, {
							        delay:10,
							        minChars:2,
							        matchSubset:1,
							        autoFill:false,
							        matchContains:1,
							        cacheLength:1,
							        selectFirst:false,
							        formatItem:function(item){return item[0];},
							        maxItemsToShow:10,
							        extraParams:{action:'userAutocomplete'}
							    })
								.result(function(event,item)
									{
										var id = $(this).attr("id").replace(/item_company_user_(\d+)/,"$1");
										$("#item_company_user_id_"+id).attr("value",item[1]);
									}
								);
						break;
					}
	            }
	            else
	            {
	            	$.facebox(req.responseJS.output);
	            }
			}
	    }
	    try_add_new_block = items_qnty;try_add_new_block++;
	    // Prepare request object (automatically choose GET or POST).
	    req.open(null, obj.PathToAjaxBackend, true);
		req.send({items_qnty:try_add_new_block,action:obj.action,template:obj.FormTemplate,var_items_qnty:obj.qnty_elem});
	}
	this.remForm = function()
	{
		var obj = this;
		var items_qnty = $('#'+obj.qnty_elem).attr("value");
		//alert(items_qnty);
	    if(items_qnty > 0)
	    {
	        $("#"+obj.ItemNamePrefix+"_"+items_qnty).remove();
	    	items_qnty--;
	        $('#'+obj.qnty_elem).attr("value",items_qnty);
	    }
	    else return false;
	}
};
// ContactForm
var ContactForm = new FormClass;
ContactForm.qnty_elem = 'contacts_qnty';
ContactForm.wrapper = 'contacts';
ContactForm.ItemNamePrefix = 'contact';
ContactForm.FormTemplate = module.tmpl_dir+'/ContactForm.html';
// EducationForm
var EducationForm = new FormClass;
EducationForm.qnty_elem = 'educations_qnty';
EducationForm.wrapper = 'educations';
EducationForm.ItemNamePrefix = 'education';
EducationForm.FormTemplate = module.tmpl_dir+'/EducationForm.html';
// ExperienceForm
var ExperienceForm = new FormClass;
ExperienceForm.qnty_elem = 'experiences_qnty';
ExperienceForm.wrapper = 'experiences';
ExperienceForm.action = 'addExperienceForm';
ExperienceForm.ItemNamePrefix = 'experience';
ExperienceForm.FormTemplate = module.tmpl_dir+'/ExperienceForm.html';
// LanguageForm
var LanguageForm = new FormClass;
LanguageForm.qnty_elem = 'languages_qnty';
LanguageForm.wrapper = 'languages';
LanguageForm.ItemNamePrefix = 'language';
LanguageForm.FormTemplate = module.tmpl_dir+'/LanguageForm.html';
// AdditionalForm
var AdditionalForm = new FormClass;
AdditionalForm.qnty_elem = 'additionals_qnty';
AdditionalForm.wrapper = 'additionals';
AdditionalForm.ItemNamePrefix = 'additional';
AdditionalForm.FormTemplate = module.tmpl_dir+'/AdditionalForm.html';
// UserForm
var UserForm = new FormClass;
UserForm.qnty_elem = 'users_qnty';
UserForm.wrapper = 'users';
UserForm.ItemNamePrefix = 'user';
UserForm.FormTemplate = module.tmpl_dir+'/UserForm.html';
// PhoneForm
var PhoneForm = new FormClass;
PhoneForm.qnty_elem = 'phones_qnty';
PhoneForm.wrapper = 'phones';
PhoneForm.ItemNamePrefix = 'phone';
PhoneForm.FormTemplate = module.tmpl_dir+'/PhoneForm.html';
